home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / graphic import.export / completed lab / drawimage.c < prev    next >
Encoding:
Text File  |  2000-10-06  |  1.7 KB  |  49 lines

  1. // Graphics Importer and Exporter Samples
  2. // This sample simply draws an image from a file using Graphics Importers
  3. // Originally written by Sam Bushell for QuickTime "Live" '99
  4. // WWDC 2000 Introduction to QuickTime
  5.  
  6. #include "MacShell.h"
  7.  
  8. void DrawImage( void )
  9. {
  10.     OSErr err = noErr;
  11.     Handle hOpenTypeList = NewHandle(0);
  12.     long  numTypes = 0;
  13.     FSSpec theFSSpec;
  14.     Rect bounds;
  15.     GraphicsImportComponent importer = 0;
  16.     WindowPtr window = NULL;
  17.     
  18.     BuildGraphicsImporterValidFileTypes( hOpenTypeList, &numTypes );
  19.     HLock( hOpenTypeList );
  20.  
  21.     err = GetOneFileWithPreview(numTypes, (OSTypePtr)*hOpenTypeList, &theFSSpec, NULL);
  22.     DisposeHandle( hOpenTypeList );
  23.     if ( err ) return;
  24.     
  25.     // locate and open a graphics importer component which can be used to draw the
  26.     // selected file. If a suitable importer is not found the ComponentInstance
  27.     // is set to NULL.
  28.     err = GetGraphicsImporterForFile( &theFSSpec,    // specifies the file to be drawn
  29.                                       &importer );    // pointer to the returned GraphicsImporterComponent
  30.         
  31.     // get the native size of the image associated with the importer                              
  32.     err = GraphicsImportGetNaturalBounds( importer,     // importer instance
  33.                                           &bounds );    // returned bounds
  34.     
  35.     OffsetRect( &bounds, 10, 45 );
  36.     window = NewCWindow( NULL, &bounds, "\pDraw Image", true, documentProc, (WindowPtr)-1, true, 0);
  37.     
  38.     // set the graphics port for drawing
  39.     err = GraphicsImportSetGWorld( importer,                // importer instance
  40.                                    GetWindowPort( window ),    // destination graphics port or GWorld
  41.                                    NULL );                    // destination GDevice, set to NULL uses GWorlds device
  42.     
  43.     // draw the image
  44.     err = GraphicsImportDraw( importer );
  45.     
  46.     // close the importer instance
  47.     CloseComponent( importer );
  48. }
  49.